#include <REGX52.H>
#include "LCD1602.h"
#include "Key.h"
#include "AT24C02.h"
#include "Delay.h"

unsigned char keyNum;
unsigned int num;

unsigned char Data;

void main() {
	
	LCD_Init();
	while (1) {
		LCD_ShowNum(1,1,num,5);
		keyNum = Key();
		if (keyNum == 1) {
			num++;
			LCD_ShowNum(1,1,num,5);
		}
		if (keyNum == 2) {
			num--;
			LCD_ShowNum(1,1,num,5);
		}
		if (keyNum == 3) {
			AT24C02_WriteByte(0,num%256);
			Delay(5);
			AT24C02_WriteByte(1,num/256);
			Delay(5);
			LCD_ShowString(2,1,"Write!");
			Delay(1000);
			LCD_ShowString(2,1,"        ");
		}
		if (keyNum == 4) {
			num = AT24C02_ReadByte(0);
			num |= AT24C02_ReadByte(1)<<8;
			LCD_ShowNum(1,1,num,5);
			LCD_ShowString(2,1,"Read!");
			Delay(1000);
			LCD_ShowString(2,1,"        ");
		}
			
	}
	
}